<script lang="tsx">
/**
 * 报销审批单
 */
export default {
  name: "daily-reimburses"
}
</script>

<script lang="tsx" setup>
import {reactive, ref} from 'vue'
import {definePageModel, PageModel} from "@/frame/view/layout/page-model/constructor.ts"
import {processRequest} from "@/frame/apis/request";
import {ElMessage, ElMessageBox} from "element-plus";
/**
 * 定义emit
 */
const emit = defineEmits<{
  (e: "confirm"): void
}>()

/**
 * 下拉列表
 */
const reflections = reactive<{
  staffList: any[];
}>({
  staffList: []
})

/**
 * 获取员工列表
 */
const getStaffList = async () => {
  const result: any = await processRequest.get("/api/Staff", {
    IsEnable: true,
    currentPage: 1,
    pageSize: 9999
  })
  reflections.staffList = result.dataList
}

getStaffList()

/**
 * 页面配置
 */
const pageModelRef = ref()
const config = definePageModel<any>({
  url: "/api/DailyReimburses",
  searchForm: {
    els: [
      {
        eType: 'el-input',
        prop: "code",
        props: {
          placeholder: "单据编码",
          clearable: true
        }
      }, {
        eType: 'el-input',
        prop: "staff",
        props: {
          placeholder: "员工姓名",
          clearable: true
        }
      }, {
        eType: 'el-select',
        prop: "status",
        props: {
          placeholder: "审核状态",
          clearable: true
        },
        optionsData: {
          list: [
            {
              label: "待审核",
              value: 0
            },
            {
              label: "审核通过",
              value: 1
            },
            {
              label: "审核不通过",
              value: 2
            }
          ],
          label: "label",
          value: "value"
        }
      }
    ]
  },
  table: {
    page: {
      enable: true,
      pageSize: 20
    },
    props: {
      stripe: false,
      border: false
    },
    operation: {
      width: 160,
      props: {
        fixed: "right"
      },
      els: [
        {
          eType: "el-button",
          label: "审核通过",
          event: "pass",
          props: {
            type: "primary",
            link: true
          },
          hide: false
        },
        {
          eType: "el-button",
          label: "审核不通过",
          event: "un-pass",
          props: {
            type: "primary",
            link: true
          },
          hide: false
        }
      ]
    },
    els: [
      {
        label: "员工编码",
        prop: "staffCode",
        minWidth: 100
      },
      {
        label: "员工姓名",
        prop: "staffName",
        minWidth: 100
      },
      {
        label: "报销时间",
        prop: "reimburseTime",
        minWidth: 100
      },
      {
        label: "审核状态",
        prop: "status",
        minWidth: 100
      },
      {
        label: "未通过原因",
        prop: "unPassRemark",
        minWidth: 100
      },
      {
        label: "金额",
        prop: "amount",
        minWidth: 100
      },
      {
        label: "报销内容",
        prop: "content",
        minWidth: 100
      },
      {
        label: "报销凭证",
        prop: "file",
        minWidth: 100
      },
      {
        label: "备注",
        prop: "remark",
        minWidth: 100
      }
    ]
  }
})

/**
 * 刷新
 */
const handleRefresh = () => {
  pageModelRef.value.refreshTableData()
}

/**
 * 审核
 */
const handlePass = async (row: any) => {
  await ElMessageBox.confirm("是否确认审核通过?", "审核", {
    type: "warning"
  })
  await processRequest.post("/api/DailyReimburses/Review", {
    id: row.id,
    isPass: true
  })
  ElMessage.success("审核通过")
  handleRefresh()
}

/**
 * 审核不通过
 */
const handleUnPass = async (row: any) => {
  const result = await ElMessageBox.prompt("理由：", "审核不通过", {
    type: "warning"
  })
  await processRequest.post("/api/DailyReimburses/Review", {
    id: row.id,
    isPass: true,
    unPassRemark: result.value
  })
  ElMessage.success("审核不通过成功")
  handleRefresh()
}
</script>

<template>
  <PageModel ref="pageModelRef" :PageModel="config" :reflections="reflections"
             @pass="handlePass" @refresh="handleRefresh" @un-pass="handleUnPass"
  />
</template>